from zflow import *

class MyRc(ZGraph):
    def __init__(self, name):
        ZGraph.__init__(self,name)
        #路由地址
        self.add_ipad(ZDatum('in',4,wire))
        #下一跳地址
        self.add_opad(ZDatum('out',4,wire))
        #本路由
        router=self.add(ZDatum('id',4,register))
        router.init = 'router_id'

        #计算路由
        self.out.val = 'in[0:1] == router_id[0:1]? in[2:3]>router_id[2:3]? router_id[0:1]|router_id[2:3]+1:router_id[0:1]|router_id[2:3]-1 : in[0:1] > router_id[0:1]? router_id[0:1]+1|router_id[2:3]:router_id[0:1]-1|router_id[2:3]'



     
        


if __name__ == '__main__':
    gen_graph_code([MyRc('')],ZVlogModuleTemplate)